package logic

import (
	"community/models/mysqlinit"
	"context"
	"fmt"

	"community/communityrpc/communityrpc"
	"community/communityrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowCommentLogic {
	return &ShowCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowCommentLogic) ShowComment(in *communityrpc.ShowCommentRequest) (*communityrpc.ShowCommentResponse, error) {
	// todo: add your logic here and delete this line
	var post mysqlinit.Comment

	mysqlinit.DB.Debug().Where("id = ?", in.Id).Find(&post)

	if post.ID == 0 {
		return nil, fmt.Errorf("没有此评论，请重新输入")
	}
	return &communityrpc.ShowCommentResponse{
		UserId:   post.UserId,
		PostId:   post.UserId,
		CommText: post.CommText,
	}, nil
}
